<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>角色管理</title>
    <link rel="shortcut icon" href="favicon.ico"> 
    <link href="<%=path%>/hplus/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="<%=path%>/hplus/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="<%=path%>/hplus/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/plugins/footable/footable.core.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/plugins/dataTables/css/jquery.dataTables.min.css"/>
    <link href="<%=path%>/hplus/css/animate.min.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/style.min862f.css?v=4.1.0" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="<%=path%>/hplus/js/plugins/sweetalert/sweetalert2.min.css">

<style> 
        .caoZuo{font-size: 15px;margin: 0 4px;color:#1ab394}
</style>

</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content">
        <div class="ibox-content">
             <span id="count" class="text-navy" style="font-size:22px;">3</span>个角色
             <!-- 新增角色纳入shiro权限控制 - ZhangHao-->
             <shiro:hasPermission name="role:create">
             <button onclick="window.location.href='<%=path%>/view/ui/createRole?type=create'" class="btn btn-primary" type="button" style="float:right;">新增角色</button>
             </shiro:hasPermission>
        </div>
        <div class="ibox-content">
            <table class="display  table-striped table-bordered table-hover" id="mydataTable">
                <thead>
                    <tr>
                       <th>角色</th>
                        <th>角色描述</th>
                        <th>角色员工</th>
                        <th>操作列</th>
                    </tr>
                </thead>
                <tbody>
                   
                </tbody>
            </table>
        </div>
    </div>

    <script src="<%=path%>/hplus/js/jquery.min.js?v=2.1.4"></script>
    <script src="<%=path%>/hplus/js/bootstrap.min.js?v=3.3.6"></script>
    <script src="<%=path%>/hplus/js/plugins/chosen/chosen.jquery.js"></script>
    <script src="<%=path%>/hplus/js/plugins/jsKnob/jquery.knob.js"></script>
    <script src="<%=path%>/hplus/js/plugins/jasny/jasny-bootstrap.min.js"></script>
    <script src="<%=path%>/hplus/js/plugins/datapicker/bootstrap-datepicker.js"></script>
    <script src="<%=path%>/hplus/js/plugins/prettyfile/bootstrap-prettyfile.js"></script>
    <script src="<%=path%>/hplus/js/plugins/switchery/switchery.js"></script>
    <script src="<%=path%>/hplus/js/plugins/ionRangeSlider/ion.rangeSlider.min.js"></script>
    <script src="<%=path%>/hplus/js/plugins/iCheck/icheck.min.js"></script>
    <script src="<%=path%>/hplus/js/plugins/metisMenu/jquery.metisMenu.js"></script>
    <script src="<%=path%>/hplus/js/plugins/colorpicker/bootstrap-colorpicker.min.js"></script>
    <script src="<%=path%>/hplus/js/plugins/clockpicker/clockpicker.js"></script>
    <script src="<%=path%>/hplus/js/plugins/cropper/cropper.min.js"></script>
    
    <script type="text/javascript" src="<%=path%>/hplus/js/plugins/dataTables/jquery.dataTables.min.js"></script>
    <script src="<%=path%>/hplus/js/demo/form-advanced-demo.min.js"></script>
	<script src="<%=path%>/hplus/js/plugins/suggest/bootstrap-suggest.min.js"></script>
    <script src="<%=path%>/hplus/js/plugins/sweetalert/sweetalert2.min.js"></script>

    <script type="text/javascript" src="<%=path%>/js/marketing/dialog.js"></script>
	<script type="text/javascript" src="<%=path%>/js/marketing/public.js"></script>
	<script type="text/javascript" src="<%=path%>/js/system/menuJump.js"></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
	
    <script type="text/javascript">
    var path = "<%=path%>";
    var myDataTable;
   	var id;
   	var count;
    $(function(){
    	init();
    });
    
    function init(){
    	myDataTable = dataTable();
    }
    
    function func_dataTableReload(){
    	myDataTable.ajax.reload(function(){
    		$(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green"});
    		$('input').iCheck('uncheck');
    	});
    }
    
    
    function dataTable(){
    	return $('#mydataTable').DataTable({
    		processing: true,
    		ordering: false,
    		searching: false,
    		info: true,
    		autoWidth: true,
    		lengthChange: false,
    		"order": [[ 2, "desc" ]],
    	    language: {
    	    	emptyTable: '<div id="content_empty"  class="form-group white-bg" style="text-align:center;padding:200px 0;margin:0;">   <p>暂无点击数据</p></div>',
    	    	info: '从第 _START_ 到第 _END_ 条数据；总共有 _TOTAL_ 条记录',
    			infoEmpty: '没有数据',
    			lengthMenu: '每页显示 _MENU_ 条记录',
    			loadingRecords: '正在加载数据....',
    			processing: '正在处理数据....',
    			zeroRecords: '没有找到匹配的记录',
    			paginate: {
    				first: '首页',
    				previous: '前页',
    				next: '后页',
    				last: '尾页'
    			}
    	    },
    	    order: [[1,'desc']],
    		pageLength: 10,
    	    pagingType: 'full_numbers',
    	    columnDefs: [{
    			render: function(data, type, full) {
    				var result = "";
    				//编辑角色纳入shiro权限控制
    				result += '<shiro:hasPermission name="role:update">';
    				result += '<a batchId="'+data+'"  class="caozuo edit" href="<%=path%>/view/ui/createRole?type=edit&id='+data+'">编辑</a>';
    				result += '</shiro:hasPermission>';
    				//删除角色纳入shiro权限控制
    				result += '<shiro:hasPermission name="role:delete">';
    				result += '<a batchId="'+data+'"  class="caozuo delete" onclick="javascript:deletedDialog(\''+data+'\');">删除</a>';
    				result += '</shiro:hasPermission>';
                    return result;
                },
    			targets: 3
    		}],
    	    columns: func_columns(),
    	    serverSide: true,
    	    ajax: {
    	    	contentType: 'application/json;charset=utf-8',
    	    	type: 'POST',
    	    	url: func_AjaxUrl(),
    	    	data: function(d){
    	    		//d.cid=cid;
    				return JSON.stringify(d);
    			}
    		}
    	}).on( 'draw', function () {
    		var info=myDataTable.page.info(); 
        	$('#count').html(info.recordsTotal);

    	} );
    	
    }
    
    function func_AjaxUrl(){
    	 return path+"/role/ajaxPageData"; 
    }
    /**		
     *	设置列名，对应后台
     */
    function func_columns(){
    	var jsonArr = [
    		{"data":"name"},
    		{"data":"description"},
    		{"data":"roleUserCount"},
    		{"data":"id"},
    	];
    	return jsonArr;
    }
    
    function deletedDialog(id){
		swal({
			  title: '您确定要删除此角色吗?',
			  text: "删除后将无法恢复，请谨慎操作！",
			  type: 'warning',
			  showCancelButton: true,
			  confirmButtonColor: '#d33',
			  cancelButtonColor: '#3085d6',
			  confirmButtonText: '删除',
			  cancelButtonText:'取消'
			}).then(function () {
				deleteRole(id);
			})
	}
    
   function  deleteRole(id){
	  var url=path+"/role/ajaxDelete"
  	    $.post(url, {
			"id" : id 
		}, function(data) {
			if (data.status == 200) {
				func_dataTableReload();
				successDialog("删除成功");
			}else {
				swal({
					  title: '删除失败',
					  text: data.message,
					  type: 'error',
					  showCancelButton: true,
					  confirmButtonColor: '#d33',
					  cancelButtonColor: '#3085d6',
					  confirmButtonText: '前往修改',
					  cancelButtonText:'取消'
					}).then(function () {				
						 menuPublic("组织架构","<%=path%>/view/ui/organizational",100000210);
					})
			}
		});
    }
    
    </script>
</body>
</html>
